#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

int n, m;
struct Q {
  int u, v;
  int lca;
  int t;
  bool operator<(Q o) const { return t < o.t; }
} a[N];
int b[N];
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int f[N][20], dep[N];
int dis[N][20];
void dfs(int u, int fu, int d) {
  dep[u] = dep[fu] + 1;
  f[u][0] = fu;
  dis[u][0] = d;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u, W[i]);
  }
}
void init() {
  dfs(1, 0, 0);
  rep(j, 1, 18) rep(i, 1, n) {
    f[i][j] = f[f[i][j - 1]][j - 1];
    dis[i][j] = dis[i][j - 1] + dis[f[i][j - 1]][j - 1];
  }
}
void lca(int u, int v, int& fuv, int& duv) {
  duv = 0;
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(j, 18, 0) if (d & (1 << j)) duv += dis[u][j], u = f[u][j];
  if (u == v) {
    fuv = u;
    return;
  }
  per(j, 18, 0) if (f[u][j] != f[v][j]) {
    duv += dis[u][j] + dis[v][j];
    u = f[u][j], v = f[v][j];
  }
  duv += dis[u][0] + dis[v][0];
  fuv = f[u][0];
  return;
}
int d[N], mx, cnt;
void dfs_sum(int u, int fu) {
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs_sum(v, u);
    d[u] += d[v];
  }
  if (d[u] == cnt) mx = max(mx, dis[u][0]);
}
bool check(int x) {
  int id = upper_bound(b + 1, b + m + 1, x) - b;
  if (id > m) return true;
  cnt = m + 1 - id;
  rep(i, 1, n) d[i] = 0;
  mx = 0;
  rep(i, id, m) {
    d[a[i].u]++, d[a[i].v]++;
    d[a[i].lca]--, d[a[i].lca]--;
  }
  dfs_sum(1, 0);
  return mx + x >= b[m];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  rep(i, 1, m) cin >> a[i].u >> a[i].v;

  init();
  rep(i, 1, m) lca(a[i].u, a[i].v, a[i].lca, a[i].t);
  sort(a + 1, a + m + 1);
  rep(i, 1, m) b[i] = a[i].t;

  int l = 0, r = 3e8;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}